var wins = []
module.exports = {
    httpGet: function(url) {
        let res = http.get(url)
        let body = res.body.json()
        return body
    },
    trim: function(text) {
        return text.replace(/[,，。.·]/ig,"")
    },
    draw: function(x, y, time) {
        if(!floaty.checkPermission()) {
            floaty.requestPermission()
        }
    
        var win = floaty.rawWindow(
            <frame gravity="center" bg="#ff0000">
                <text id="text" color="#ffffff">time</text>
            </frame>
        )
        
        // wins.push(win)
        win.setPosition(x, y)
        win.setSize(200, 50)
        ui.run(function() {
            console.log('*****************UI****************')
            setTimeout(function() {
                // win.text.setText(time)
            }, 100)

            setTimeout(function () {
                console.log('=======================关闭浮窗============')
                win.close()
                
            }, 3000)
        })
    },
    requestScreenCapture: function() {
        if(!requestScreenCapture()){
            toast("请求截图失败")
            exit()
        }
        sleep(1000)
    },
    makeDir: function(path) {
        if(!files.exists(path)) {
            files.create(path)
        }
    },
    hash:function (str) {
        let hash = 0;
        for (let i = 0; i < str.length; i++) {
            const char = str.charCodeAt(i);
            hash = (hash << 5) - hash + char;
            hash |= 0; // 转换为32位整数
        }
        return hash.toString();
    }
}
